package com.auxgroup.hr.front.service.hireperson.impl;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.dao.domain.PsCHireJcxxTbl;
import com.auxgroup.hr.front.dao.domain.PsCHirePrimaryClass;
import com.auxgroup.hr.front.dao.repository.PsCHireJcxxTblRepository;
import com.auxgroup.hr.front.service.hireperson.HireJcxxService;

/** 
 * @author lvliuhao
 * @version 创建时间：180523 
 * 入职人员计算机能力service
 */
@Service("hireJcxxService")
public class HireJcxxServiceImpl implements HireJcxxService {
	private static final Logger logger = LoggerFactory.getLogger(HireEducatServiceImpl.class);
	
	@Autowired
	private PsCHireJcxxTblRepository PsCHireJcxxTblRepository;


	@Override
	public PsCHireJcxxTbl getHireJcxx(PsCHirePrimaryClass hirePrimary) {
		return PsCHireJcxxTblRepository.findOne(hirePrimary);
	}


	@Override
	public PsCHireJcxxTbl save(PsCHireJcxxTbl HireJcxx) {
		if(HireJcxx.getcSeqno()==null){
			HireJcxx.setHrsRowAddOprid(HireJcxx.getRsHireId());
			HireJcxx.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		}
		HireJcxx.setHrsRowUpdOprid(HireJcxx.getRsHireId());
		HireJcxx.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		Set<String> ignoreFields = new HashSet<String>(Arrays.asList("cSeqno"));
		ObjectFieldUtils.handleNullValue(HireJcxx, ignoreFields);
		return PsCHireJcxxTblRepository.save(HireJcxx);
	}


	@Override
	public Boolean delete(PsCHirePrimaryClass hirePrimary) {
		try {
			PsCHireJcxxTblRepository.delete(hirePrimary);
		} catch (Exception e) {
			logger.error("delete HireJcxx error: hirePrimary={}",hirePrimary,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCHireJcxxTbl> getAll(String rsHireId) {
		PsCHireJcxxTbl HireJcxx = new PsCHireJcxxTbl();
		HireJcxx.setRsHireId(rsHireId);
		return PsCHireJcxxTblRepository.findAll(Example.of(HireJcxx),new Sort(Sort.Direction.DESC,"cDate"));
	}


	
	
	
}
